package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.DrugClassification;
import com.example.springboot.entity.DrugDetails;
import com.example.springboot.entity.User;
import com.example.springboot.service.DrugService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug")
public class DrugController {

    @Resource
    DrugService drugService;

    /*
     * 分页查询
     * @param pageNum:当前页码
     * @param pageSize:每页显示条数
     */
    @GetMapping("/drugClassification/selectDrugClassificationPage")
    public Result selectDrugClassificationPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             DrugClassification drugClassification){
        PageInfo<DrugClassification> drugClassificationPageInfo = drugService.selectDrugClassificationPage(pageNum, pageSize, drugClassification);
        return Result.success(drugClassificationPageInfo);
    }

    @PostMapping("/drugClassification/addDrugClassification")
    public Result addDrugClassification(@RequestBody DrugClassification drugClassification)  //@RequestBody 接收前端传来的json数据
    {
        drugService.addDrugClassification(drugClassification);
        return Result.success();//不需要返回数据，不用传递
    }

    @PutMapping("/drugClassification/updateDrugClassification")
    public Result updateDrugClassification(@RequestBody DrugClassification drugClassification)  //@RequestBody 接收前端传来的json数据
    {
        drugService.updateDrugClassification(drugClassification);
        return Result.success();//不需要返回数据，不用传递
    }

    @DeleteMapping("/drugClassification/deleteDrugClassification/{id}")
    public Result deleteDrugClassification(@PathVariable Integer id) // @PathVariable 接收路径中的参数
    {
        drugService.deleteDrugClassificationById(id);
        return Result.success();
    }

    @DeleteMapping("/drugClassification/deleteBatchDrugClassification")
    public Result deleteBatchDrugClassification(@RequestBody List<DrugClassification> drugClassificationList) // 传递的不只有一个对象，所以用List
    {
        drugService.deleteBatchDrugClassification(drugClassificationList);
        return Result.success();
    }

    /*
     * 分页查询
     * @param pageNum:当前页码
     * @param pageSize:每页显示条数
     */
    @GetMapping("/drugClassification/selectDrugDetailsPage")
    public Result selectDrugDetailsPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                               @RequestParam(defaultValue = "10") Integer pageSize,
                                               DrugDetails drugDetails){
        PageInfo<DrugDetails> drugDetailsPageInfo = drugService.selectDrugDetailsPage(pageNum, pageSize, drugDetails);
        return Result.success(drugDetailsPageInfo);
    }

    @PostMapping("/drugClassification/addDrugDetails")
    public Result addDrugDetails(@RequestBody DrugDetails drugDetails)  //@RequestBody 接收前端传来的json数据
    {
        drugService.addDrugDetails(drugDetails);
        return Result.success();//不需要返回数据，不用传递
    }

    @GetMapping("/drugDetails/selectDrugClassificationAll")
    public Result selectDrugClassificationAll(){
        List<DrugClassification> drugClassificationList = drugService.selectDrugClassificationAll();
        return Result.success(drugClassificationList);
    }

    @PutMapping("/drugDetails/updateDrugDetails")
    public Result updateDrugDetails(@RequestBody DrugDetails drugDetails)  //@RequestBody 接收前端传来的json数据
    {
        drugService.updateDrugDetails(drugDetails);
        return Result.success();//不需要返回数据，不用传递
    }
}
